package net.huashitong.ssydt.provider.pk.service;


import net.huashitong.ssydt.base.dao.LongMapper;
import net.huashitong.ssydt.base.service.AbstractLongService;
import net.huashitong.ssydt.pk.entity.SsPkYzddMyMedal;
import net.huashitong.ssydt.provider.pk.mapper.SsPkYzddMyMedalMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author <a href="mailto:yhy23456@163.com">huiyang.yu</a>
 * @since 2017.12.20
 */
@Service
@Transactional
public class SsPkYzddMyMedalServiceImpl extends AbstractLongService<SsPkYzddMyMedal> implements SsPkYzddMyMedalService {

    private SsPkYzddMyMedalMapper mapper;

    @Autowired
    public SsPkYzddMyMedalServiceImpl(SsPkYzddMyMedalMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    protected LongMapper<SsPkYzddMyMedal> getLongMapper() {
        return this.mapper;
    }

    @Override
    public SsPkYzddMyMedal getByUserId(String userId) {
        return this.mapper.getByUserId(userId);
    }

    @Override
    public SsPkYzddMyMedal getAutoCreateByUserId(String userId) {
        SsPkYzddMyMedal ssPkYzddMyMedal = this.getByUserId(userId);
        if (ssPkYzddMyMedal == null) {
            ssPkYzddMyMedal = new SsPkYzddMyMedal();
            ssPkYzddMyMedal.setUserId(userId);
            ssPkYzddMyMedal.setGoldMedal(0);
            ssPkYzddMyMedal.setSilverMedal(0);
            ssPkYzddMyMedal.setBronzeMedal(0);
            this.mapper.insertSelective(ssPkYzddMyMedal);
        }
        return ssPkYzddMyMedal;
    }

    @Override
    public List<SsPkYzddMyMedal> findCountMedalRank() {
        return this.mapper.findCountMedalRank();
    }

    @Override
    public List<String> findXuebaXunZhang() {
        return this.mapper.findXuebaXunZhang();
    }
}
